import http from "@/api";
import { ReqPage, ResPage } from "@/api/interface";

const baseUrl: string = "/queue/delay_queue_meta";

export interface DelayQueueMetaPageParam extends ReqPage {
  // 队列名称
  name?: string;
}

export interface DelayQueueMetaPageResult {
  // 主键id
  id: string;
  // 队列名称
  name: string;
  // 最后加载时间
  lastLoadTime: string;
  // 预加载间隔
  preloadDistance: string;
  // 预加载时长
  preloadDuration: string;
  // 时间单位 参考字典: TimeUnits
  timeUnit: number;
}

export const getDelayQueueMetaPage = (param: DelayQueueMetaPageParam) => {
  return http.get<ResPage<DelayQueueMetaPageResult>>(baseUrl + `/page`, param);
};

export interface DelayQueueMetaInfoResult {
  // 主键id
  id: string;
  // 队列名称
  name: string;
  // 最后加载时间
  lastLoadTime: string;
  // 预加载间隔
  preloadDistance: number;
  // 预加载时长
  preloadDuration: number;
  // 时间单位 参考字典: TimeUnits
  timeUnit: number;
}

export const getDelayQueueMetaInfo = (id: string) => {
  return http.get<DelayQueueMetaInfoResult>(baseUrl + `/info/` + id);
};

export interface DelayQueueMetaSaveParam {
  // 队列名称
  name: string;
  // 预加载间隔
  preloadDistance?: number;
  // 预加载时长
  preloadDuration?: number;
  // 时间单位 参考字典: TimeUnits
  timeUnit?: number;
}

export const saveDelayQueueMeta = (param: DelayQueueMetaSaveParam) => {
  return http.post(baseUrl + `/save`, param);
};

export interface DelayQueueMetaUpdateParam {
  // 主键id
  id?: string;
  // 队列名称
  name?: string;
  // 预加载间隔
  preloadDistance?: number;
  // 预加载时长
  preloadDuration?: number;
  // 时间单位 参考字典: TimeUnits
  timeUnit?: number;
}

export const updateDelayQueueMeta = (param: DelayQueueMetaUpdateParam) => {
  return http.post(baseUrl + `/update`, param);
};

export const deleteDelayQueueMeta = (ids: string[]) => {
  return http.post(baseUrl + `/delete`, ids);
};
